package com.enjoyor.soa.traffic.core.tsms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.ls.LSInput;

import com.enjoyor.soa.traffic.core.tsms.domain.RltRoutePost;
import com.enjoyor.soa.traffic.core.tsms.mapper.IRltRoutePostMapper;
import com.enjoyor.soa.traffic.core.tsms.service.IRltRoutePostService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;

@Service
@Transactional
@SuppressWarnings("rawtypes")
public class RltRoutePostService implements IRltRoutePostService{

	@Autowired
	private IRltRoutePostMapper iRltRoutePostMapper;
	
	@Autowired
	private IPubLogMapper iPubLogMapper;
	
	@Override
	public Page getRltRoutePostPage(Page page, String taskId, String routeId, String postId, String isHandle) {
		// TODO Auto-generated method stub
		Map<String,Object> mapBean = new HashMap<>();
		mapBean.put("taskId", taskId);
		mapBean.put("routeId", routeId);
		mapBean.put("postId", postId);
		mapBean.put("isHandle", isHandle);
		page.setMapBean(mapBean);
		return iRltRoutePostMapper.selectPageInfo(page);
	}

	@Override
	public List<RltRoutePost> getRltRoutePostList(String taskId, String routeId, String postId, String isHandle) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<>();
		map.put("taskId", taskId);
		map.put("routeId", routeId);
		map.put("postId", postId);
		map.put("isHandle", isHandle);
		return iRltRoutePostMapper.getRltRoutePostList(map);
	}

	@Override
	public void deleteRltRoutePost(String postId, String personName) {
		// TODO Auto-generated method stub
		iRltRoutePostMapper.deleteById(postId);
		iPubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
                String.format("删除岗位信息:{%s} 操作成功!", new Object[] { postId }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_RLT_POST_MANAGEMENT.getMessage());
	}

	@Override
	public void insertRltRoutePost(RltRoutePost rltRoutePost, String personName) {
		// TODO Auto-generated method stub
		String postId = "RP"+ TimeHelper.getUniqueString();
		rltRoutePost.setPostId(postId);
		rltRoutePost.setIsDelete(false);
		rltRoutePost.setIsHandle(false);
		iRltRoutePostMapper.insert(rltRoutePost);
		iPubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("添加岗位信息:{%s} 操作成功!", new Object[] { rltRoutePost.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_RLT_POST_MANAGEMENT.getMessage());
	}

	@Override
	public void editRltRoutePost(RltRoutePost rltRoutePost, String personName) {
		// TODO Auto-generated method stub
		rltRoutePost.setIsDelete(false);
		rltRoutePost.setIsHandle(false);
		iRltRoutePostMapper.updateByIdSelective(rltRoutePost);
		iPubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
                String.format("更新岗位信息:{%s} 操作成功!", new Object[] { rltRoutePost.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_RLT_POST_MANAGEMENT.getMessage());
	}

	@Override
	public void rltRoutePostList(List<RltRoutePost> list, String taskId, String routeId, String personName) {
		// TODO Auto-generated method stub
		//删除线路关联的所有岗位信息；
		iRltRoutePostMapper.delPostByRouteId(routeId);
		int postSortno = 1;
		for(int i = 0;i<list.size();i++){
			RltRoutePost rltRoutePost = list.get(i);
			rltRoutePost.setPostId("RP"+ TimeHelper.getUniqueString());
			rltRoutePost.setTaskId(taskId);
			rltRoutePost.setRouteId(routeId);
			rltRoutePost.setIsDelete(false);
			rltRoutePost.setIsHandle(false);
			rltRoutePost.setPostSortno(postSortno);
			iRltRoutePostMapper.insert(rltRoutePost);
			postSortno++;
		}
		iPubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("关联岗位:{%s} 操作成功!", new Object[] { routeId }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_RLT_POST_MANAGEMENT.getMessage());
	}

}
